const dayjs = require('dayjs');
const { getBlogListReq } = require('./src/views/getSourceBlog');
const handleBlogDetail = require('./src/views/handleBlogDetail');
const excelWithimage = require('./src/views/excelWithimage');

const { action } = process.env;

const source = require('./blog_list_source.json');
const saveAsDoc = require('./src/views/saveAsDoc');

switch (action) {
  case 'list':
    getBlogListReq();

    break;
  case 'detail':
    handleBlogDetail();
    break;

  case 'excel':
    excelWithimage();
    break;
  case 'doc':
    const list = source.map(blog => {
      return {
        createdAt: dayjs(blog.created_at).format('YYYY-MM-DD HH:mm'),
        textRaw: blog.text_raw,
        imageList: blog.pic_ids
          ? blog.pic_ids.map(key => {
              const item = blog.pic_infos[key].original; //内有url,width和height
              return { image: item.url };
            })
          : []
      };
    });
    saveAsDoc(list);
    break;
  default:
    getBlogListReq();
}
